package y24.m5.sql;

import y24.m5.sql.data.Student;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;
public class StudetMapper {
    public List<Student> showStudent(Connection connection) throws SQLException {
        String sql = "select * from student";
        PreparedStatement statement = connection.prepareStatement(sql);
        ResultSet resultSet = statement.executeQuery();
        List<Student> students = new ArrayList<>();

        while (resultSet.next()) {
            Student student = new Student();
            student.setName(resultSet.getString("name"));
            student.setAge(resultSet.getInt("age"));
            student.setSex(resultSet.getInt("sex"));
            student.setBirth(resultSet.getString("birth"));
            student.setNation(resultSet.getString("nation"));
            student.setNativePlace(resultSet.getString("native_place"));
            student.setIdCard(resultSet.getString("id_card"));
            student.setHouse(resultSet.getString("house"));
            student.setMajorId(resultSet.getInt("major_id"));
            students.add(student);
        }

        resultSet.close();
        statement.close();
        return students;
    }
}
